# This is the comet part of the djando server. It will receive many request from the client and answer them if they need to send update requests

from django.http import HttpResponse
from django.utils import simplejson
from market.models import Player
from market.authentification import authentificatePlayer
from market.models import MarketPlacePlayerMarketUpToDateStatus
from market.cometHelper import getMarketPlacePlayerStatus
from market.models import ChatRoomPlayerUpToDateStatus
from market.cometHelper import getChatRoomPlayerStatus



###########################################################################################
# return if the player is up to date
def getMarketUpToDateStatus(request):
        # authentification
        player_list = [] #the player with a dummy initialisation
        alternative_response_list = [] #the answer to return if the player could not be authentificated with a dummy initialisation
        if not( authentificatePlayer( request, player_list, alternative_response_list ) ):
                return alternative_response_list[0]
        playerStatus = getMarketPlacePlayerStatus( player_list[0].dbPlayer )        
        return HttpResponse( simplejson.dumps([{"isUpToDate":playerStatus.isUpToDateStatusForTheMarket}] ), mimetype='application/javascript')
        
 



###########################################################################################
# return if the player is up to date
def getChatUpToDateStatus(request):
        # authentification
        player_list = [] #the player with a dummy initialisation
        alternative_response_list = [] #the answer to return if the player could not be authentificated with a dummy initialisation
        if not( authentificatePlayer( request, player_list, alternative_response_list ) ):
                return alternative_response_list[0]
        playerStatus = getChatRoomPlayerStatus( player_list[0].dbPlayer )
        return HttpResponse( simplejson.dumps([{"isUpToDate":playerStatus.isUpToDateStatusForTheChat}] ), mimetype='application/javascript')
        
 

